package baidu.com.matedemo.pair;

import android.app.Activity;

import com.baidu.duer.smartmate.out.DuerDevice;
import com.baidu.duer.smartmate.out.oauth.IResponseCallback;

/**
 * Created by niufei01 on 2018/2/1.
 * V2协议配网后的授权步骤封装
 */

public class DevicePairWrapper {
    private IDevicePair mDevicePair;

    public void startPair(final Activity activity,
                           final OauthType type,
                           final DuerDevice duerDevice,
                           final IResponseCallback callback) {
        if (activity == null || type == null || duerDevice == null || callback == null) {
            return;
        }

        if (OauthType.DEVICE_CODE.equals(type)) {
            mDevicePair = new DeviceCodePair();
        } else if (OauthType.AUTHORIZATION_CODE.equals(type)) {
            // oauthCode 授权方式 标准接入方案
            if (duerDevice.getConfigNetworkVersion() == 3) {
                mDevicePair = new OauthCodePairV3();
            } else {
                mDevicePair = new OauthCodePairV2();
            }
        } else if (OauthType.PRIVILEGE_OAUTH.equals(type)) {
            // privilege 授权方式
            if (duerDevice.getConfigNetworkVersion() == 3) {
                mDevicePair = new PrivilegePairV3();
            } else {
                mDevicePair = new PrivilegePairV2();
            }
        }
        if (mDevicePair != null) {
            mDevicePair.startPair(activity, duerDevice, callback);
        }
    }

    public void stopPair() {
        if (mDevicePair != null) {
            mDevicePair.stopPair();
        }
    }
}
